package com.hntxk.cqzd.export.controller;/**
 * @ClassName: ${user}
 * @Author:liuqing
 * @Description
 * @Date: Created in 21:28 2020/9/22
 * @Modified By:
 */

import com.hntxk.core.framework.action.BaseController;
import com.hntxk.cqzd.export.model.ConsultationExport;
import com.hntxk.cqzd.export.model.ExcelExportConstant;
import com.hntxk.cqzd.export.model.QueryParamModel;
import com.hntxk.cqzd.export.service.ConsultationExportService;
import com.hntxk.cqzd.export.util.ExcelUtil;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @ClassName ConsultationExportController
 * @description 会诊信息web层
 * @Author Liuqing
 * @Date 2020/9/22 21:28
 * @Version 1.0
 */
@Api(value="会诊信息导出", tags={"[SP]会诊信息导出"})
@Controller
@RequestMapping("cqzd/Consultation")
@Slf4j
public class ConsultationExportController extends BaseController {

    private final ConsultationExportService service;


    public ConsultationExportController(@Qualifier("consultationService") ConsultationExportService service) {
        super();
        this.service = service;
    }

    @ResponseBody
    @RequestMapping(value = "/selConsultationAll",method = RequestMethod.GET)
    public String selDiagnosisAll(@ModelAttribute QueryParamModel model, HttpServletResponse response){
        //获取查询结果导出excel
        List<ConsultationExport> consultationExports = service.selConsultationAll(model);

        Date currentTime = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        ExcelUtil.generateExcelSaveLocal(consultationExports,
                ExcelExportConstant.CONSULTATION_TITLE,
                ExcelExportConstant.CONSULTATION_FIELD,
                response,formatter.format(currentTime).replace(" ","-").replace(":","-"));
        return "success";
    }
}
